﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using EmployeeManager.Core;

namespace EmployeeManager.View
{
    public partial class FormChinh : Form
    {
        public FormChinh()
        {
            InitializeComponent();
        }

        private void groupBox1_Enter(object sender, EventArgs e)
        {

        }

      
        private void textBox1_TextChanged(object sender, EventArgs e)
        {
            //string cn = "select * from NHANSU";
            SqlConnection conn = new SqlConnection(@"Data Source=HIENTHAO-PC\SQLSEVER;Initial Catalog=QLNHANSU_BTL;Integrated Security=True");
            //SqlDataAdapter adapter = new SqlDataAdapter(cmdstr, conn);
            DataTable data = new DataTable();
           
            da.Fill(data);
            DataView dtv = data.DefaultView;
            dtv.RowFilter = string.Format("MANV like '%{0}%' or TENNV like '%{0}%'", txtTimKiem.Text);
            dataGridViewNhanSu.DataSource = dtv;
        }
        private SqlConnection conn;
        private DataTable dt = new DataTable("NHANSU");
        private SqlDataAdapter da = new SqlDataAdapter();
        private void FormChinh_Load(object sender, EventArgs e)
        {
            //string cmdstr = "select * from NHANSU";
            //SqlConnection conn = new SqlConnection(@"Data Source=HIENTHAO-PC\SQLSEVER;Initial Catalog=QLNHANSU_BTL;Integrated Security=True");
            //SqlDataAdapter adapter = new SqlDataAdapter(cmdstr, conn);
            //DataTable data = new DataTable();
            //adapter.Fill(data);
            //DataView dtv = dt.DefaultView;
            //dtv.RowFilter = "";
            //dataGridViewNhanSu.DataSource = dtv;
            //dataGridViewNhanSu.DataSource = null;
            //DataView dtv = dt.DefaultView;
            
            //dtv.FindRows(txtTimKiem.Text);
            string cn = "Data Source=(local);Initial Catalog=QLNHANSU_BTL;Integrated Security=True";
            conn = new SqlConnection(cn);
            SqlCommand cmd = new SqlCommand();
            cmd.Connection = conn;
            cmd.CommandType=CommandType.Text;
            cmd.CommandText = "select * from NHANSU";
            da.SelectCommand = cmd;
            da.Fill(dt);
            DataView dtv = dt.DefaultView;
            dtv.RowFilter = "";
            dataGridViewNhanSu.DataSource = dtv;
            //dataGridViewNhanSu.DataSource = null;
            dtv = dt.DefaultView;
            
           
        }

        private void groupBox2_Enter(object sender, EventArgs e)
        {

        }

        private void btnThaydoi_Click(object sender, EventArgs e)
        {
            FormChitiet fm = new FormChitiet();
            fm.Show();
            this.Hide();
        }

    }
}
